package cn.dgut.vinko.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.dgut.vinko.domain.Employee;
import cn.dgut.vinko.repository.EmpRepository;

@Service
public class EmpService {

	@Autowired
	EmpRepository empRepository;

	private List<Employee> getAllEmpList() {
		return empRepository.findAll();
	}

	private Employee saveEmp(Employee employee) {
		return empRepository.save(employee);
	}

	private void deleteEmp(Employee employee) {
		empRepository.delete(employee);
	}

	private Employee findByEmpName(String empName) {
		return empRepository.findByEmpName(empName);
	}

	// 登录
	public boolean login(Employee employee) {
		//查找用户
		Employee loginEmp = findByEmpName(employee.getEmpName());

		if (loginEmp != null && loginEmp.getPassword().equals(employee.getPassword())) {
			return true;
		} else {
			return false;
		}
	}

	// 注册
	public boolean register(Employee employee) {
		saveEmp(employee);
		return true;
	}

}
